package day02;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestNotifyAndWait {
    // 对象锁
    private static final Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {


        Thread t1 = new Thread("t1") {
            public void run() {
                synchronized (lock) {
                    log.debug("t1线程开始执行");
                    try {
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    log.debug("剩余业务t1");
                }
            }
        };



        Thread t2 = new Thread("t2") {
            public void run() {
                synchronized (lock) {
                    log.debug("t2线程开始执行");
                    try {
                        lock.wait(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                    log.debug("剩余业务t2");
                }
            }
        };
        t2.setPriority(10);
        t2.start();
        t1.setPriority(2);
        t1.start();


        // 主线程睡两秒
//        Thread.sleep(2000);
//        synchronized (lock){
////            lock.notify();
//            lock.notifyAll();
//        }
    }
}
